﻿Imports System.Data.OleDb
Public Class EditArtist
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then




            tb_User.Text = User.Identity.Name

            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("3dBuzzDatabase").ConnectionString)
            Dim sqlString As String = "SELECT aspnet_Users.[UserId], Artists.[ASPUserName], Artists.[Title], Artists.[Firstname], Artists.[Surname],Artists.[Nickname], Artists.[Companyname], Artists.[WebURL], Artists.[Email], Artists.[Addr1], Artists.[Addr2], Artists.[Town], Artists.[County], Artists.[Country], Artists.[Postcode], Artists.[TelMobile], Artists.[Fax], Artists.[Telcomp] FROM aspnet_Users INNER JOIN Artists ON aspnet_Users.[UserId] = Artists.[ASPUserName] WHERE aspnet_Users.[UserName] = @f1"
            Dim cmd As OleDbCommand = New OleDbCommand(sqlString, oleDbConn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
            oleDbConn.Open()


            Dim dataReader = cmd.ExecuteReader()

            If (dataReader.HasRows) = False Then
                Response.Redirect("NoArtistError.aspx")
            End If

            dataReader.Read()

            tb_EditTitle.Text = dataReader.Item("Title")
            tb_EditFName.Text = dataReader("Firstname")
            tb_EditSurname.Text = dataReader("Surname")
            tb_EditNickname.Text = dataReader.Item("Nickname")
            tb_EditCompany.Text = dataReader.Item("Companyname")
            tb_EditWeb.Text = dataReader.Item("WebURL")
            tb_EditEmail.Text = dataReader.Item("Email")
            tb_EditAddr1.Text = dataReader.Item("Addr1")
            tb_EditAddr2.Text = dataReader.Item("Addr2")
            tb_EditTown.Text = dataReader.Item("Town")
            tb_EditCounty.Text = dataReader.Item("County")
            tb_EditCountry.Text = dataReader.Item("Country")
            tb_EditPostcode.Text = dataReader.Item("Postcode")
            tb_EditMobile.Text = dataReader.Item("TelMobile")
            tb_EditFax.Text = dataReader.Item("Fax")
            tb_EditCoNumber.Text = dataReader.Item("Telcomp")



        End If


    End Sub

    Protected Sub btn_EditArtist_Click(sender As Object, e As EventArgs) Handles btn_EditArtist.Click
        Dim oleDbConn2 As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("3dBuzzDatabase").ConnectionString)
        Dim sqlUpdateString As String = "UPDATE Artists INNER JOIN aspnet_Users ON aspnet_Users.[UserId] = Artists.[ASPUserName] SET Artists.[Title]= @f21, Artists.[Firstname]=@f22, Artists.[Surname] = @f23, Artists.[Nickname]=@f24, Artists.[Companyname] = @f25, Artists.[WebURL]=@f26, Artists.[Email]=@f27, Artists.[Addr1] = @f28, Artists.[Addr2]=@f29, Artists.[Town] = @f30, Artists.[County] = @f31, Artists.[Country] = @f32, Artists.[Postcode] = @f33, Artists.[TelMobile] = @f34, Artists.[Fax] = @f35, Artists.[Telcomp] = @f36  WHERE aspnet_Users.[UserName] = @f20"

        Dim updatecmd As OleDbCommand = New OleDbCommand(sqlUpdateString, oleDbConn2)
        updatecmd.CommandType = CommandType.Text

        updatecmd.Parameters.AddWithValue("@f21", tb_EditTitle.Text)
        updatecmd.Parameters.AddWithValue("@f22", tb_EditFName.Text)
        updatecmd.Parameters.AddWithValue("@f23", tb_EditSurname.Text)
        updatecmd.Parameters.AddWithValue("@f24", tb_EditNickname.Text)
        updatecmd.Parameters.AddWithValue("@f25", tb_EditCompany.Text)
        updatecmd.Parameters.AddWithValue("@f26", tb_EditWeb.Text)
        updatecmd.Parameters.AddWithValue("@f27", tb_EditEmail.Text)
        updatecmd.Parameters.AddWithValue("@f28", tb_EditAddr1.Text)
        updatecmd.Parameters.AddWithValue("@f29", tb_EditAddr2.Text)
        updatecmd.Parameters.AddWithValue("@f30", tb_EditTown.Text)
        updatecmd.Parameters.AddWithValue("@f31", tb_EditCounty.Text)
        updatecmd.Parameters.AddWithValue("@f32", tb_EditCountry.Text)
        updatecmd.Parameters.AddWithValue("@f33", tb_EditPostcode.Text)
        updatecmd.Parameters.AddWithValue("@f34", tb_EditMobile.Text)
        updatecmd.Parameters.AddWithValue("@f35", tb_EditFax.Text)
        updatecmd.Parameters.AddWithValue("@f36", tb_EditCoNumber.Text)

        updatecmd.Parameters.AddWithValue("@f20", User.Identity.Name)

        oleDbConn2.Open()
        updatecmd.ExecuteNonQuery()
        oleDbConn2.Close()
        oleDbConn2.Dispose()
        Response.Redirect("~/Artists.aspx")

    End Sub
End Class